#
#	redMine - Instant Mobile Feedback (IMF) Plugin
#	Author: Bartłomiej Twardowski
#	Date: 16/06/2010
#

require File.dirname(__FILE__) + '/imf_plugin_app_controller'

class CommentController < IMFPluginApplicationController

  	accept_key_auth :get_for_issue, :add

	def get_for_issue
		issue=Issue.find(params[:id] || params[:issue_id] || (params[:issue] && params[:issue][:id]))
		journals = issue.journals.find(:all, :conditions => ["notes IS NOT NULL"])
		respond_to do |format|
         	format.html {}
          	format.xml  { render :xml => journals }
	    end
	end


	def add
		issue=Issue.find(params[:comment][:issue_id])
		user = User.find_by_login( params[:comment][:user_login])
		notes = params[:comment][:note]
		journal = issue.init_journal(user, notes)
		out = issue.save
		
		respond_to do |format|
         	format.html {}
          	format.xml { render :xml => out }
	    end
	end
	
end
